﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1;
using OutlookCalendar.Model;

namespace OutlookCalendar.Controls
{
    public class CalendarAppointmentItem : ContentControl
    {    
        static CalendarAppointmentItem()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CalendarAppointmentItem), new FrameworkPropertyMetadata(typeof(CalendarAppointmentItem)));
        }

        #region StartTime/EndTime

        public static readonly DependencyProperty StartTimeProperty =
            TimeslotPanel.StartTimeProperty.AddOwner(typeof(CalendarAppointmentItem));

        public bool StartTime
        {
            get { return (bool)GetValue(StartTimeProperty); }
            set { SetValue(StartTimeProperty, value); }
        }

        public static readonly DependencyProperty EndTimeProperty =
            TimeslotPanel.EndTimeProperty.AddOwner(typeof(CalendarAppointmentItem));

        public bool EndTime
        {
            get { return (bool)GetValue(EndTimeProperty); }
            set { SetValue(EndTimeProperty, value); }
        }

        public static readonly DependencyProperty BgColorProperty =
            TimeslotPanel.BgColorProperty.AddOwner(typeof(CalendarAppointmentItem));

        public Brush BgColor
        {
            get { return (Brush)GetValue(BgColorProperty); }
            set { SetValue(BgColorProperty, value); }
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            //this.Foreground=Brushes.Red;

            Functionality.appointmentSelected = null;
            try
            {
                foreach (Appointment ap in Functionality.appointments)
                {
                    if (ap.StartTime.Equals((DateTime)GetValue(StartTimeProperty)) && ap.EndTime.Equals((DateTime)GetValue(EndTimeProperty)))
                    {
                        Functionality.appointmentSelected = ap;
                        Paint();

                    }
                }
            }
            catch (Exception ex) { }
        }

        protected void Paint()
        {
           // MessageBox.Show(this.Height.ToString());
        }

        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            Functionality.appointmentSelected = null;
            try
            {
                foreach (Appointment ap in Functionality.appointments)
                {
                    if (ap.StartTime.Equals((DateTime)GetValue(StartTimeProperty)) && ap.EndTime.Equals((DateTime)GetValue(EndTimeProperty)))
                    {
                        Functionality.appointmentSelected = ap;

                    }
                }
            }
            catch (Exception ex) { }
           // MessageBox.Show(GetValue(StartTimeProperty).ToString() + " " + GetValue(EndTimeProperty).ToString());

            

           // MessageBox.Show(e.OriginalSource.ToString());
           // Functionality.appointments.Add(appointment);
           // Functionality.appointments.Remove(appointment);
            //OutlookCalendar.Controls.Calendar ci = (OutlookCalendar.Controls.Calendar)e.Source;
            
            //ci.DataContext = Functionality.appointments;
            //ci.FilterAppointments();
        }

        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);
            //bet kuri tuscia celle kalendoriuje
        }
             

        #endregion

    }
}
